package com.common_used_class._02stringbuffer;

import java.math.BigInteger;
import java.util.Scanner;

/**
 * @Author WaveHi
 * @Date 9/8/2021 下午 3:00
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description StringBuffer的使用
 */
public class TestStringBuffer {

    public static void main(String[] args) {

        //获取StringBuffer对象
        StringBuffer stringBuffer = new StringBuffer(20);

        //获取stringBuffer对象的字符长度
        System.out.println(stringBuffer.length());

        //获取StringBuffer对象的容量
        System.out.println(stringBuffer.capacity());

        //向StringBuffer对象添加数据
        System.out.println(stringBuffer.append("10"));

        //向StringBuffer对象插入数据
        System.out.println(stringBuffer.insert(1,"10"));

        //设定字符序列的长度
        stringBuffer.setLength(14);
        System.out.println(stringBuffer.capacity());
        System.out.println(stringBuffer.length());
        System.out.println(stringBuffer);

        //删除
        StringBuffer s4 = stringBuffer;
        s4.delete(1,2);
        System.out.println(s4);
        s4.deleteCharAt(0);
        System.out.println(s4);


        //修改
        stringBuffer.insert(1,"abc");

        //替换
        stringBuffer.replace(0,2,"Wow!");

        //拓展
        stringBuffer.append("It is very good,is not it?");
        System.out.println(stringBuffer.capacity());
        BigInteger b1 = new BigInteger("10");
        System.out.println(b1.remainder(new BigInteger("3")));

    }

}
